﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sahit.iSoilHotel.Application.MainBoundedContext.Tavern.Interfaces;
using Sahit.iSoilHotel.Domain.MainBoundedContext.Tavern.Aggregates.CustomerAgg;
using Sahit.iSoilHotel.Domain.Seedwork;

namespace Sahit.iSoilHotel.Application.MainBoundedContext.Tavern.Services
{
    public class CustomerService:ICustomerService
    {
        private readonly ICustomerRepository customerRepository;

        public CustomerService(ICustomerRepository customerRepository)
        {
            this.customerRepository = customerRepository;
        }

        public bool CheckIsOldCustomer(string customerIDCard)
        {
            return customerRepository.GetFiltered(m => m.IDCard.Equals(customerIDCard)).Any();
        }

        public Customer AddNewCustomer(Customer customer)
        {
            customer.GenerateNewIdentity();
            customerRepository.Add(customer);
            return customer;
        }

        public Customer GetCustomer(string customerIDCard)
        {
            return customerRepository.GetFiltered(m => m.IDCard.Equals(customerIDCard)).FirstOrDefault();
        }
    }
}
